package com.fqxiny.lease.web.admin.custom.interceptors;

import com.fqxiny.lease.common.exception.UpException;
import com.fqxiny.lease.common.result.ResultCodeEnum;
import com.fqxiny.lease.common.utils.JWTUtil;
import io.jsonwebtoken.Claims;
import io.minio.credentials.Jwt;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author : 戚欣扬
 * @code : 登陆保护
 */
@Component
public class LoginIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String accessToken = request.getHeader("access_token");
        if (accessToken == null){
            throw new UpException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }
        Claims claims = JWTUtil.parseToken(accessToken);
        return true;
    }
}


